<template>
  <div class="supplier-details">
    <div class="company-info-wrap">
      <div class="avatar">
        <img :src="info.merchant.mer_avatar" alt="">
      </div>
      <div class="info">
        <div class="title">{{ info.merchant.mer_name }}</div>
        <div class="certification">
          <div class="item">
            <img src="~/assets/images/settle-date.png" alt="">
            入驻{{ info.merchant.create_time }}
          </div>
          <div class="item">
            <img src="~/assets/images/certification.png" alt="">
            {{info.merchant.authentication}}
          </div>
          <div class="item">
            <img src="~/assets/images/diamond.png" alt="">
            钻石买家
          </div>
          <div class="item star">
            <img src="~/assets/images/score-star.png" alt="">
            综合评分：<span class="score">4.8</span>/5.0
          </div>
        </div>
      </div>
    </div>

    <div class="rank">
      <p class="title">您在{{info.merchant.mer_name}}公司的采购分类排名：</p>
      <div class="content">
        <div class="item" :class="index === 2 && 'myself'" v-for="(item, index) in info.overhead" :key="index">
          <div class="index">NO.{{ index + 1 }}</div>
          <div class="name">{{item}}</div>
        </div>
      </div>
      <div class="total">共采购：{{ info.total_price }}元</div>
    </div>

    <div class="table-wrap">
      <div class="head">
        <div class="title">采购记录</div>
        <m-button type="bordered">导出</m-button>
      </div>

      <div class="table">
        <Table :data="info.record" :border="true">
          <table-column prop="pay_time" label="时间" align="center" width="190"/>
          <table-column prop="store_name" label="商品名称" align="center"/>
          <table-column prop="total_num" label="数量" align="center" width="120"/>
          <table-column label="单价" align="center" width="120">
            <template v-slot="{ row }">
              ￥{{ row.price }}
            </template>
          </table-column>
          <table-column label="总额" align="center">
            <template v-slot="{ row }">
              {{ row.total_price }}元
            </template>
          </table-column>
        </Table>
      </div>

      <m-pagination :pagination="page"/>
    </div>
  </div>
</template>

<script>
import MButton from '@/components/common/m-button/MButton'
import MPagination from '@/components/common/m-pagination/MPagination'
import { Table, TableColumn } from 'element-ui'
import {merchantDetailInfo} from '@/request/api'

export default {
  name: 'SupplierDetails',
  components: { MPagination, MButton, Table, TableColumn },
  data() {
    return {
      records: [],
      page: 1,
      limit: 10,
      info: {
        merchant:{},
        overhead:[],
        record:[],
        total_price: 0
      }
    }
  },
  created() {
    this.getMerInfo()
  },
  methods: {
    getMerInfo() {
      let id = this.$route.query.id;
      merchantDetailInfo({id,page:this.page,limit:this.limit}).then(res => {
        if(res.status !== 200) return this.$message.error(res.message)
        this.info = res.data;
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/style/common.scss";

.supplier-details {
  .company-info-wrap {
    display: flex;
    margin-bottom: 30px;

    .avatar {
      width: 230px;
      height: 120px;
      margin-right: 15px;
      border: 1px solid #e2e2e2;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    .info {
      display: flex;
      flex-direction: column;
      padding: 10px 0;

      .title {
        font-size: 20px;
        margin-bottom: 30px;
      }

      .certification {
        display: flex;
        font-size: 14px;

        .item {
          margin-right: 15px;
          display: flex;
          align-items: center;

          img {
            margin-right: 5px;
          }

          .score {
            color: $theme-color-1;
          }
        }
      }
    }
  }

  .rank {
    border-bottom: solid 1px #eaeaea;
    padding-bottom: 30px;
    margin-bottom: 30px;

    > .title {
      margin-bottom: 40px;
    }

    > .content {
      margin-bottom: 40px;

      > .item {
        width: 20%;
        display: inline-flex;

        .index {
          font-size: 18px;
          margin-right: 15px;
        }
      }

      .myself {
        color: $theme-color-1;
      }
    }

    > .total {
      font-size: 20px;
      color: $theme-color-1;
      font-weight: bold;
    }
  }

  .table-wrap {
    .head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 15px;
    }

    .table {
      margin-bottom: 15px;

      /deep/ .el-table th, .el-table tr {
        background-color: #F3F4F7;
        color: #666;
        border: none;
        border-bottom: solid 1px #eaeaea;
      }
    }
  }
}
</style>
